<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ES6解构赋值和三点扩展运算符</title>
</head>
<body>
<script>
  /**
   * 解构赋值
       左右两边结构必须一样
       右边必须有值
       声明和赋值不能分开
   */
    //解构赋值
    let arr = [4,5,6];
    //普通赋值
    let a = arr[0]
    let b = arr[1]
    let c = arr[2]
    console.log(a);
    console.log(b);
    console.log(c);
    //解构赋值
    let [x,y,z] = ['a','cc545',7];
    console.log(x);
    console.log(y);
    console.log(z);

    const obj = {name:'yuanxi',sex:'男',sss:789}
  //普通赋值
  //   let name = obj.name;
  //   let sex = obj.sex;
  //   let sss = obj.sss;
  //   console.log(name);
  //   console.log(sex);
  //   console.log(sss);
    //解构赋值
  let {name,sex,sss} = obj;
  console.log(name);
  console.log(sex);
  console.log(sss);
  //复杂的结构
  const objs = [['a','b'],111,{names:'zhansan',ss:787},'word'];
  let [[n,m],q,{names,ss},o] = objs;
  console.log(n);
  console.log(m);
  console.log(q);
  console.log(names);
  console.log(ss);
  console.log(o);
  /**
   * 扩展运算符
       ...三点运算符
       展开数组
       默认参数
   */

  let arr1 = [11,12,13]
  let arr2 = [45,46,47]
  let arr3 = [...arr1,1,2,4,...arr2]
  console.log(arr1);
  console.log(arr2);
  console.log(arr3);

  function demo(x,y,z){
    console.log(x);
    console.log(y);
    console.log(z);
  }
  demo(...arr1);
  function fun1(a,b,...args){
    console.log(args);
  }
  fun1(8,0,4,7,9,'aaaa');
  let [l,xm] = [1,3,4];
  console.log(l);
  console.log(xm);
</script>
</body>
</html>